/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ucjava.chat.admanager;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;

/**
 *
 * @author Jonathan Davis
 */
public class AdvertisingImpl extends UnicastRemoteObject implements Remote, IAdvertising {

    // String to be used by RMI for binding
    public static final String PURCHASEADVERTISEMENTS = "PurchaseAdvertisements";
    //intialization of linked list
    LinkedList<String> adList = new LinkedList<String>();
    Advertisement randomAd = new Advertisement();

    public AdvertisingImpl() throws RemoteException {
        //these should add to positions 1,2,3 respectively the ads.
        //this should be run at the startup of the server.
        adList.add("Buy Glop, Glop the best sticky substance there is!");
        adList.add("If you want free software visit virus.org!");
        adList.add("Visit BlueXephos on youtube to see more great Minecraft content!");
        adList.add("Sim City, create a city in your image!");
        adList.add("Join the Terran Republic for the glory!");
        adList.add("Visit plantplaces.com!");
        adList.add("Have a good time at The Hofbrauhaus!");
        adList.add("Papa Johns, large 1 topping for $8.99!");
        adList.add("They're watching you, Person of Interest (Thursdays 9PME)");
    }

    /**
     *
     * @param ads
     */
    @Override
    public void sellAds(String Ads) throws RemoteException {
        //this line of code takes the string passed into the method from the UI layer and adds
        //it to the LinkedList
        boolean exists = adList.contains(Ads);
        if (exists == false) {
            adList.add(Ads);
        }
    }

    @Override
    //method that when called upon returns an ads similar; to the getadvertisment() method from
    //programming assignment 1
    public String pushAds() throws RemoteException {
        int adNum = adList.size();
        int RandomVariable = (int) (Math.random() * adNum);
        String AdPush = adList.get(RandomVariable);
        //System.out.println();
        if (RandomVariable > -1 && RandomVariable < 10) {
            return AdPush;
        } else {
            adList.remove(RandomVariable);
            return AdPush;
        }
        //return AdPush;
    }
}
